import java.util.ArrayList;
import java.util.LinkedList;

/**
 * @author wtcode
 * @date 2021/2/8 - 21:49
 */
public class Offer06 {

    public int[] reversePrint(ListNode head) {
        LinkedList<Integer> stack = new LinkedList<>();
        while (head != null) {
            stack.addLast(head.val);
            head = head.next;
        }
        int[] array = new int[stack.size()];
        for (int i = 0; i < stack.size(); i++) {
            array[i] = stack.removeLast();
        }

        return array;

    }

}

class ListNode{
    int val;
    ListNode next;
    ListNode(int x) { val = x; }
}
